<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>watchEffect基础用法-2</title>
</head>

<body>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    <h1>测试数据：</h1>a：{{a}}，
    <button @click="click">点击</button>
  </div>
  <script>
    const App = Vue.createApp({
      setup() {
        let a = Vue.ref(1);

        Vue.watchEffect(() => {
          //当变量a变化时，即执行当前函数
          console.log("变量a变化了", a.value);
        });

        const click = () => {
          a.value += 1;
        };

        return {
          a,
          click,
        };
      },

    });
    App.mount("#Application");
  </script>
</body>

</html>